package com.dream.keigezhushou.Activity.acty.personal;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.BaseActivity;
import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyRingActivity extends BaseActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_ring)
    ListView lvRing;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_ring);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("铃声");
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        //ListView创建适配器
        lvRing.setAdapter(new RingAdapter());
    }


    class RingAdapter extends BaseAdapter {

        int count = 25;
        private View inflater;
        private Dialog dialog;
        private RelativeLayout rlSetRing;
        private RelativeLayout rlSetClock;
        private RelativeLayout rlShare;
        private RelativeLayout rlDelete;

        public RingAdapter() {
            super();
        }

        @Override
        public int getCount() {
            return count;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder mHolder = null;
            if (convertView == null){

                convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_ring_iten,null);

                mHolder = new ViewHolder();

                mHolder.ivMore = (ImageView) convertView.findViewById(R.id.iv_dialog);
                convertView.setTag(mHolder);
            }else {
                mHolder = (ViewHolder)convertView.getTag();
            }


//            mHolder.ivMore.setOnClickListener(new View.OnClickListener() {
//
//
//
//                @Override
//                public void onClick(View v) {
//                    Toast.makeText(getApplicationContext(),"按钮被点击了",Toast.LENGTH_SHORT).show();
//                    //从底部弹出选择弹窗
//                    dialog = new Dialog(getApplicationContext());
//                    inflater = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_ring_diglog1,null);
//
//                    //找到弹窗中的控件
//                    rlSetRing = (RelativeLayout) inflater.findViewById(R.id.rl_set_ring);
//                    rlSetClock = (RelativeLayout) inflater.findViewById(R.id.rl_set_clock);
//                    rlShare = (RelativeLayout) inflater.findViewById(R.id.rl_share);
//                    rlDelete = (RelativeLayout) inflater.findViewById(R.id.rl_delete);
//
//                    dialog.setContentView(inflater);
//
//                    Window window = dialog.getWindow();
//
//                    WindowManager manager = getWindowManager();
//                    WindowManager.LayoutParams params = window.getAttributes();
//                    Display display = manager.getDefaultDisplay();
//                    params.width = display.getWidth();
//                    window.setGravity(Gravity.BOTTOM);
//                    dialog.show();
//
//                    //点击条目，弹窗消失
//                    rlSetRing.setOnClickListener(this);
//                }
//            });
            return convertView;
        }


        class ViewHolder{

            TextView tvSong,tvSinger;
            ImageView ivMore;
        }

    }


}
